import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:xiongan_app_yy/pages/common/LoadBuilder.dart';
import 'package:xiongan_app_yy/provider/automounting_provider.dart';
import 'package:xiongan_app_yy/provider/into_warehousing_provider.dart';
import 'package:xiongan_app_yy/widgets/comm/left_icon_widget.dart';
import 'package:xiongan_app_yy/widgets/into_warehousing_item.dart';

class IntoWarehousing extends StatefulWidget {
  @override
  _IntoWarehousingState createState() => _IntoWarehousingState();
}

class _IntoWarehousingState extends State<IntoWarehousing> {
  List<dynamic> _data = List();

  Future<void> _refresh() async {
    await Future.delayed(Duration(seconds: 1), () {
      return null;
    });
    Provider.of<IntoWareHousingProvider>(context).getList();
  }

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) async {
      Provider.of<IntoWareHousingProvider>(context).getList();
    });
  }

  @override
  Widget build(BuildContext context) {
    _data = Provider.of<IntoWareHousingProvider>(context).listData;
    return Scaffold(
      appBar: AppBar(
        leading: LeftIconWidget(icon: Icons.chevron_left, isize: 36),
        backgroundColor: Color(0XFF00A5F1),
        title: Text(
          "入库作业",
          style: TextStyle(fontSize: 18),
        ),
        actions: <Widget>[
          new IconButton(
            // action button
            padding: EdgeInsets.only(),
            iconSize: 22,
            icon: new Icon(IconData(0xe617, fontFamily: "wuIconFont")),
            onPressed: () {
              Navigator.pushNamed(context, "/warehousingSearchPage");
            },
          )
        ],
        elevation: 0,
        centerTitle: true,
      ),
      body: LoadBuilder(
        visibility: Provider.of<IntoWareHousingProvider>(context).netStatus1,
        emptyVisibility:!Provider.of<IntoWareHousingProvider>(context).netStatus1&&_data.length==0,
        builder: Column(
          children: <Widget>[
            Expanded(
                child: RefreshIndicator(
                    child: ListView.builder(
                        itemBuilder: (BuildContext context, int index) {
                          return IntoWareHousingItem(_data[index], index,
                              (id, name) {
                            if (name.contains("待入库")||name.contains("清点中")) {
                              Navigator.pushNamed(context, '/invCounterDetails',
                                  arguments: _data[index]);
                            } else if (name.contains("交接") || name.contains("清点完成")) {
                              Navigator.pushNamed(context, '/into_handover_details', arguments: _data[index]);
                            } else if (name.contains("上架")) {
                              Provider.of<AutoMountingProvider>(context).getDetailListData(orderid: _data[index]['id']);
                              Provider.of<AutoMountingProvider>(context).setOrderId(_data[index]['id']);
                              Navigator.pushNamed(
                                  context, '/auto_mounting_type');
                            }
                          });
                        },
                        itemCount: _data.length),
                    onRefresh: _refresh)),
          ],
        ),
      ),
    );
  }
}




